from pathlib import Path
import shutil
import random

p = Path('a/b/c/d')
s = Path('a')
d = Path('dst')
l = [chr(x) for x in range(97, 123)]

if s.exists():
    shutil.rmtree(s)
    
# 递归创建目录
p.mkdir(parents=True, exist_ok=True)

def touch_file(path, num):
    if path.exists:
        for i in range(num):
            filename = ''.join(random.sample(l,4))
            (path / filename).touch(exist_ok=True)
    else:
        return "path is not exist"

# 忽略文件
def ignore(src, names):
    ig = filter(lambda name: not (Path(src, name).is_dir() or name.startswith('x') or name.startswith('y') or name.startswith('z')),names)
    return set(ig)

# Path('a/b/c/d')每层目录创建50个普通文件
touch_file(p, 50)
for i in p.parents:
    if i != Path('.'):
        touch_file(i, 50)

# 复制a目录内的文件到dst目录
if d.exists():
    shutil.rmtree(d)
shutil.copytree(s,d,ignore=ignore)
print(list(d.rglob('*')))

# 做的不错